import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

function loadCurrentUser() {
  const user = sessionStorage.getItem("CURRENT_USER");
  if(user) {return JSON.parse(user)};
  return {}; 
};

export default new Vuex.Store({
  state: {
    currentUser:loadCurrentUser(),
  },
  getters: {
  },
  mutations: {
    setCurrentUser(state, payload) {
      state.currentUser = payload;
      sessionStorage.setItem("CURRENT_USER", JSON.stringify(payload));
    }
  },
  actions: {
  },
  modules: {
  }
})
